﻿using System;

namespace Widgetsphere.Core.DataAccess
{	
	/// <summary>
	/// A field sort object for the RegionPaging object.
	/// </summary>
	[Serializable]
	public partial class PagingFieldItem<E> : IPagingFieldItem
		where E : struct, IConvertible
	{
		/// <summary>
		/// Determines the direction of the sort.
		/// </summary>
		public bool Ascending { get; set; }

		/// <summary>
		/// Determines the field on which to sort.
		/// </summary>
		public E Field { get; set; }

		/// <summary>
		/// Create a sorting field object for the RegionPaging object.
		/// </summary>
		/// <param name="field">The field on which to sort.</param>
		public PagingFieldItem(E field)
		{
			this.Field = field;
		}

		/// <summary>
		/// Create a sorting field object for the RegionPaging object.
		/// </summary>
		/// <param name="field">The field on which to sort.</param>
		/// <param name="ascending">Determines the direction of the sort.</param>
		public PagingFieldItem(E field, bool ascending)
			: this(field)
		{
			this.Ascending = ascending;
		}

		#region IPagingFieldItem Members

		System.Enum IPagingFieldItem.GetField()
		{
			//return (Enum)this.Field;
			return (System.Enum)Enum.Parse(typeof(E), this.Field.ToString());
		}

		#endregion

	}

}
